package com.tangruojie.controller;

import com.tangruojie.domain.Code;
import com.tangruojie.domain.Result;
import com.tangruojie.domain.query.PageQuery;
import com.tangruojie.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/user-address")
public class UserAddressController {

    private final IUserService userService;

    @GetMapping("/query")
    public Result queryUserAddress() {
        return new Result(
                Code.GET_SUCCESS,
                "查询成功",
                userService.selectUserWithAddress()
        );
    }

    @GetMapping("/get")
    public Result getUserAddress() {
        return new Result(
                Code.GET_SUCCESS,
                "查询成功",
                userService.getUserWithAddress()
        );
    }

    @GetMapping("/queryPage")
    public Result queryUserAddressPage(@ModelAttribute PageQuery pageQuery) {
        return new Result(
                Code.GET_SUCCESS,
                "查询成功",
                userService.selectUserWithAddressPage(pageQuery)
        );
    }

    @GetMapping("/getPage")
    public Result getUserAddressPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize
    ) {
        return new Result(
                Code.GET_SUCCESS,
                "查询成功",
                userService.getUserWithAddressPage(pageNum, pageSize)
        );
    }

}
